import API from '../../api/api.js'
const app = getApp()

Component({
  /**
   * 组件的属性列表
   */
  properties: {
    screenHeight: Number
  },

  /**
   * 组件的初始数据
   */
  data: {
    screenHeight:app.globalData.screenHeight,
    CustomBar:app.globalData.CustomBar,
    article: {}

  },

  ready: function () {

  },

  /**
   * 组件的方法列表
   */
  methods: {
    onEditorReady() {
      const that = this
      wx.showLoading({
        title: '加载中...',
        mask:true
      })
      API.getRandomArticle("wenzhangbiao",1).then(res=>{
        let data = res[0]
        that.createSelectorQuery().select('#readonlyeditor').context(function (res) {
          that.editorCtx = res.context
          if(data.neiRong !=""){
          that.editorCtx.setContents({
            html: data.neiRong
          })
        }
        }).exec()
        this.setData({
          data: res[0]
        })
        wx.hideLoading()
      })
      
      
    },
    onNextFunc:function(e){
      const that = this
      that.editorCtx.clear()
      wx.showLoading({
        title: '加载中...',
        mask:true
      })
      API.getRandomArticle("wenzhangbiao",1).then(res=>{
        let data = res[0]
        that.createSelectorQuery().select('#readonlyeditor').context(function (res) {
          that.editorCtx = res.context
          if(data.neiRong !=""){
            that.editorCtx.setContents({
              html: data.neiRong
            })
          }
        }).exec()
        this.setData({
          data: res[0]
        })
        wx.hideLoading()
      })
    },
    onDetailFunc:function(e){
      let item = e.currentTarget.dataset.value
      wx.navigateTo({
        url: "/pages/wenzhangdetail/wenzhangdetail?id=" + item._id
      })

    }
  }
})